package indi.zhifa.recipe.bailan.busy.auth.dao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import indi.zhifa.recipe.bailan.busy.auth.entity.po.DeviceEntity;
import indi.zhifa.recipe.bailan.busy.auth.dao.mapper.DeviceMapper;
import indi.zhifa.recipe.bailan.busy.auth.dao.service.IDeviceDbService;
import indi.zhifa.recipe.bailan.framework.mysql.entity.annotations.ZfDbService;
import indi.zhifa.recipe.bailan.framework.mysql.service.impl.ZfDbServiceImpl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 设备表 服务实现类
 * </p>
 *
 * @author 织法
 * @since 2022-12-19
 */
@CacheConfig(cacheNames = "sys_device")
@ZfDbService(name = "DeviceEntity")
public class DeviceDbServiceImpl extends ZfDbServiceImpl<DeviceMapper, DeviceEntity> implements IDeviceDbService {

    @Cacheable(value = "sys_device-byCode",key = "#pCode",condition = "#result!=null")
    @Override
    public Long findByCode(String pCode) {
        LambdaQueryWrapper lambdaQueryWrapper = Wrappers.<DeviceEntity>lambdaQuery()
                .eq(DeviceEntity::getCode,pCode);
        DeviceEntity deviceEntity = findOne(lambdaQueryWrapper);
        if(null != deviceEntity){
            return deviceEntity.getId();
        }
        return null;
    }

}
